package model.container;

/**
 * 
 * @author Wim 
 * A container class that can be used to instantiate a given amount
 *         of Student instances that can be used for testing purposes.
 * 
 */

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import model.Registration;
import model.Student;
import model.generator.RegistrationGenerator;
import model.generator.StudentGenerator;

public class StudentContainer {

	private static StudentContainer studentContainer;

	private List<Student> students;

	/* Make sure the class cannot be instantiated */
	private StudentContainer() {
		this.students = new ArrayList<Student>();

	}

	public void generateData() {
		try {
			students = StudentGenerator.generateStudents(35);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	/** Constructs a new student container object if none exists */
	public static StudentContainer getInstance() {
		if (studentContainer == null) {
			studentContainer = new StudentContainer();
		}
		return studentContainer;
	}

	/** Return the list of students */
	public List<Student> getStudents() {
		return students;
	}

	/** Set the list of students */
	public void setStudents(ArrayList<Student> students) {
		this.students = students;
	}

	/** Returns the number of students in the container */
	public int getStudentCount() {
		return students.size();
	}

	/** Clear the container */
	public void clear() {
		this.students.clear();
	}

	/** Add a student to the list */
	public void addStudent(Student student) {
		students.add(student);
	}

	/** Remove a student from the list */
	public void removeStudent(Student student) {
		students.remove(student);
	}

	/** Prints all students in the collection **/
	public String printAllStudents() {
		String s = new String();
		for (Student student : students) {
			s += student.toString() + "\n";
		}
		return s;
	}

	public void finishInitialisation() {
		StudentGenerator.finishStudentInitialisation();
	}

	/** Searches for a student with a specified ID */
	public Student getStudentByID(String id) {
		for (Student student : this.students) {
			if (student.getStudentNumber().equals(id)) {
				return student;
			}
		}
		return null;
	}

}
